# variables
a = 1
b = 2.3
c = "These Violent Delights Have Violent Ends"
d = True
for i in [a, b, c, d]:
    print(type(i), i)
print('*' * 10)


# data structure
my_tuple = (1, 5, 'a')
print(my_tuple[1])
my_list = [2, 6, 'b']
print(my_list[1])
my_dict = {'a': 1, 'b': 2, 3: 4}
print(my_dict['a'])
print(my_dict[3])
print('*' * 10)


# condition
tobe = True
if tobe or not tobe:
    print('That is the question.')
print('*' * 10)


# loop
e = 27
counter = 0
for j in range(1000):
    if e == 1:
        break
    if e % 2 == 0:
        e = e // 2
    else:
        e = e * 3 + 1
    counter += 1
print(counter)
print('*' * 10)


# function
def my_plus(x, y):
    return x + y


print(my_plus(3, 4))
plus_2 = lambda x: my_plus(x, 2)
print(plus_2(4))
print('*' * 10)


# class
class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def move(self, a=0, b=0):
        self.x += a
        self.y += b

    def where_am_i(self):
        print(f'My location is ({self.x}, {self.y})')


p = Point(2, 2)
p.where_am_i()
p.move(1, 0)
p.where_am_i()
print('*' * 10)


# I/O
with open('tutorial.py', 'r') as f:
    lines = f.readlines()
    for line in lines:
        if 'data' in line:
            break
        print(line.rstrip())
print('*' * 10)


# Exception
try:
    g = 1 / 0
except:
    print('Something is wrong')
finally:
    g = 0
print(g)
print('*' * 10)


if __name__ == '__main__':
    print('Hello world!')
